package o2o.web.actions.user;

import com.jinyou.utils.common.DateUtils;
import com.jinyou.utils.common.ObjectUtils;
import com.jinyou.utils.common.ToolUtils;
import com.jinyou.utils.common.ValidateUtil;
import com.jinyou.utils.security.EncrypMD5;
import com.jinyouapp.common.tools.jms.model.JMSNotify;
import o2o.business.sms.UserSMSInfoParams;
import o2o.cache.agent.AgentManagerMemory;
import o2o.cache.postman.CityPostmanMemory;
import o2o.cache.user.UserInfoExtraMemory;
import o2o.cache.user.UserInfoMemory;
import o2o.cache.user.UserOnlineImpl;
import o2o.cache.user.UserPwdMemory;
import o2o.config.dao.MongoDaoImpl;
import o2o.config.dao.UserDaoSql;
import o2o.config.dao.utils.Expression;
import o2o.config.dao.utils.QueryCondition;
import o2o.config.jms.config.JMSTypeContent;
import o2o.config.jms.sender.JmsSender;
import o2o.dao.PO.PojoTables;
import o2o.dao.PO.agent.AgentManagerInfo;
import o2o.dao.PO.common.IsBindAccount;
import o2o.dao.PO.common.ResultInfo;
import o2o.dao.PO.common.UserType;
import o2o.postman.model.CityPostman;
import o2o.dao.PO.user.UserInfo;
import o2o.dao.PO.user.UserInfoExtra;
import o2o.dao.PO.wallet.UserWallet;
import o2o.dao.VO.user.UserInfoVO;
import o2o.system.Common;
import o2o.system.data.PROMPTS;
import o2o.system.data.SYS_CONFIG_PATH;
import o2o.system.data.SYS_SETTINGS;
import o2o.web.actions.wallet.WalletAction;
import org.apache.commons.lang.StringUtils;
import java.security.NoSuchAlgorithmException;
import java.sql.Connection;
import java.sql.SQLException;
import java.util.HashMap;
import java.util.List;

public class UserLogin {


    //登录 mod
    public static ResultInfo loginV2(String username, String password, int loginUserType, String devJson) {
        return login(true, username, loginUserType, false, true, password, "", false, devJson);
    }

    //通过验证码登录 mod
    public static ResultInfo loginByTelCode(String username, String telCode, int loginUserType, String devJson) {
        return login(false, username, loginUserType, true, false, "", telCode, false, devJson);
    }

    // 第三方的token，登录（阿里云一键登录，获取到用户手机号后，直接登录）
    public static ResultInfo loginByTriToken(String username) {
        return login(false, username, UserType.USER, false, false, null, null, false, null);
    }

    //通过微信openid和验证码登录
    public static ResultInfo loginByTelCodeAndWxOpenId(String username, String telCode, int loginUserType, String password, Boolean isXcx_) {
        return login(false, username, loginUserType, true, false, password, telCode, isXcx_, null);
    }

    public static ResultInfo loginByWxOpenId(String appFlag, String wxOpenId, int loginUserType) {
        return loginByWxOpenId(appFlag, wxOpenId, loginUserType, 0);
    }

    //微信登录
    public static ResultInfo loginByWxOpenId(String appFlag, String wxOpenId, int loginUserType, int needBindAccount) {    // needBindAccount 不传或者传0，代表不需要绑定账号
        UserInfo userInfo = UserInfoMemory.getInstance().getUserInfoByOpenId(wxOpenId);
        if (null == userInfo) {

            if (0 == IsBindAccount.Bind - needBindAccount) { // 需要绑定
                return new ResultInfo("绑定失败！");
            } else {
                //用户不存在，注册一个用户
                ResultInfo resultInfo = login(false, wxOpenId, loginUserType, false, false, "", "", false, null);
                String filed = "wxOpenId";
                if (ValidateUtil.isNotNull(appFlag)) {
                    filed = "wxOpenId2";
                }
                //获取到用户的openId后存到用户信息
                StringBuffer sb = new StringBuffer();
                sb.append("update ").append(PojoTables.UserInfo).append(" set ").append(filed).append("='").append(wxOpenId)
                        .append("',updateUser='admin_wx_response' where username = '").append(wxOpenId).append("' and delFlag =0");
                System.out.println(sb.toString());
                try {
                    UserDaoSql.getInstance().executeBySql(sb.toString());
                } catch (SQLException e) {
                    e.printStackTrace();
                    return new ResultInfo("保存用户的微信openId失败，请稍后再试");
                }
                UserInfoMemory.getInstance().modifyUserInfo(wxOpenId);
                try {
                    JMSNotify notify = JMSNotify.getInstance().setType(JMSTypeContent.USER_INFO_MODIFY).setStr01(wxOpenId);//o2o.business.jms  MQDataBusiness
                    JmsSender.setTopicSender(notify);
                } catch (Exception e) {
                }
                if (ValidateUtil.isNull(wxOpenId)) {
                    return new ResultInfo("微信openId不能为空");
                }
                return resultInfo;
            }

        } else {
            return login(true, userInfo.getUsername(), loginUserType, false, false, "", "", false, null);
        }

    }

    //微信小程序登录
    public static ResultInfo loginByWxXcxOpenId(String appFlag, String wxXcxOpenId, int loginUserType, int needBindAccount) {    // needBindAccount 不传或者传0，代表不需要绑定账号
        UserInfo userInfo = UserInfoMemory.getInstance().getUserInfoByXcxOpenId(wxXcxOpenId);
        if (null == userInfo) {
            if (0 == IsBindAccount.Bind - needBindAccount) { // 需要绑定
                return new ResultInfo("绑定失败。");
            } else {
                //用户不存在，注册一个用户
                ResultInfo resultInfo = login(false, wxXcxOpenId, loginUserType, false, false, "", "", false, null);
                String filed = "wxXcxOpenId";
                if (ValidateUtil.isNotNull(appFlag)) {
                    filed = "wxXcxOpenId2";
                }
                //获取到用户的openId后存到用户信息
                StringBuffer sb = new StringBuffer();
                sb.append("update ").append(PojoTables.UserInfo).append(" set ").append(filed).append("='").append(wxXcxOpenId)
                        .append("',updateUser='admin_wx_xcx_response' where username = '").append(wxXcxOpenId).append("' and delFlag =0");
                System.out.println(sb.toString());
                try {
                    UserDaoSql.getInstance().executeBySql(sb.toString());
                } catch (SQLException e) {
                    e.printStackTrace();
                    return new ResultInfo("保存用户的微信openId失败，请稍后再试");
                }
                UserInfoMemory.getInstance().modifyUserInfo(wxXcxOpenId);
                try {
                    JMSNotify notify = JMSNotify.getInstance().setType(JMSTypeContent.USER_INFO_MODIFY).setStr01(wxXcxOpenId);
                    JmsSender.setTopicSender(notify);
                } catch (Exception e) {
                }
                if (ValidateUtil.isNull(wxXcxOpenId)) {
                    return new ResultInfo("微信openId不能为空");
                }
                return resultInfo;
            }

        } else {
            return login(true, userInfo.getUsername(), loginUserType, false, false, "", "", false, null);
        }

    }


    public static UserInfoVO loginNotCheck(String username) {
        if (ValidateUtil.isNull(username)) {
            return null;
        }
        UserInfo userInfo = UserInfoMemory.getInstance().getUserInfo(username);
        //返回token
        String token = ToolUtils.getToken();
        //缓存token
        UserOnlineImpl.getInstance().add(token, username);
        //返回用户信息
        UserInfoVO userInfoVO = new UserInfoVO();
        try {
            ObjectUtils.copyPropertiesExclude(userInfo, userInfoVO, null);
        } catch (Exception e) {
            e.printStackTrace();
            return null;
        }
        if (null != userInfoVO) {
            if (ValidateUtil.isNotNull(userInfoVO.getSignPhoto()) && ValidateUtil.isNotNetUrl(userInfoVO.getSignPhoto())) {
//                userInfoVO.setSignPhoto(Common.imageUrl + userInfoVO.getSignPhoto());
                userInfoVO.setSignPhoto(SYS_CONFIG_PATH.IMAGE_BASE_URL + userInfoVO.getSignPhoto());
            }
        }
        userInfoVO.setToken(token);
        //记录日志
        LoginLogMan.addLogin(username);

        return userInfoVO;
    }

    //注册1  mod
    public static ResultInfo registerByTelCode(String username, boolean isCheckTelCode, String password, String telCode, boolean isCheckService, String email, String devJson) {
        if (ValidateUtil.isNull(username)) {
//            return new ResultInfo("请先输入手机号");
            return new ResultInfo(PROMPTS.ENTER_YOUR_MOBILE);
        }
        if (isCheckTelCode && ValidateUtil.isNull(telCode)) {
//            return new ResultInfo("注册失败，验证码不能为空");
            return new ResultInfo(PROMPTS.VERIFICATION_CODE_EMPTY);
        }
        //验证是否已经存在当前帐号
        QueryCondition query = QueryCondition.getInstance();

        if (User.isPhoneLogin()) {
            query.addCondition(Expression.getInstance().addChild("phone", username).addChild("delFlag", 0));
        } else {
            query.addCondition(Expression.getInstance().addChild("delFlag", 0).addChild("username", username));
        }
        int count;
        try {
            count = UserDaoSql.getInstance().getCount(PojoTables.UserInfo, query);
        } catch (SQLException e) {
            e.printStackTrace();
//            return new ResultInfo("注册用户时失败，请稍后再试");
            return new ResultInfo(PROMPTS.FAILED_REGISTER_USER);
        }
        if (count > 0) {
//            return new ResultInfo("当前手机号已经注册，请直接登录");
            return new ResultInfo(PROMPTS.MOBILE_IS_ALREADY);
        }

        if (isCheckTelCode) {
            if (ValidateUtil.isNull(telCode)) {
//                return new ResultInfo("注册失败，请填写验证码");
                return new ResultInfo(PROMPTS.VERIFICATION_CODE_EMPTY);

            } else {
                // 判断验证码是否正确
                HashMap<String, Object> map = new HashMap<String, Object>();
                map.put("username", username);
                List<HashMap<String, Object>> list = MongoDaoImpl.getInstance().find(UserSMSInfoParams.MonUserSMSDB, UserSMSInfoParams.MonUserSMSRegCol, map, 1);
                if (list == null || list.size() < 1) {
//                    return new ResultInfo("请获取验证码");
                    return new ResultInfo(PROMPTS.GET_VERIFICATION_CODE);
                }
                System.out.println(list.get(0).get("telCode"));
                System.out.println(list.get(0).get("telCode"));
                // if (list.get(0).get("telCode") == null || list.get(0).get("telCode").toString().indexOf(telCode) < 0) {
                if (list.get(0).get("telCode") == null
                        || !list.get(0).get("telCode").toString().contains("\"" + telCode + "\"")) {
//                    return new ResultInfo("请输入正确的验证码！");
                    return new ResultInfo(PROMPTS.ENTER_CORRECT_VERIFY_CODE);
                }
            }
        }

        String realUsername = User.getUniqueUserName(username);
        if (StringUtils.isEmpty(realUsername)) {
            return new ResultInfo("操作用户失败,请稍后重试");
        }

        Integer hasSetPsw = 1;
        //  add by yangtk 2019年5月24日19:31:16 检测密码是否传入  未传入则再次赋值
        if (ValidateUtil.isNull(password)) {
            hasSetPsw = 0;
            password = "123456";
            if (null != SYS_SETTINGS.SHOP_DEFAULT_PSW && 0 == 1 - SYS_SETTINGS.SHOP_DEFAULT_PSW) {
                if (StringUtils.isNotEmpty(username) && username.length() > 11) {
                    password = username.substring(5, 11);
                }
            }
        }
        // end
        //密码加密处理
        try {
            password = EncrypMD5.eccrypt(password);
        } catch (Exception e) {
            e.printStackTrace();
//            return new ResultInfo("密码加密失败");
            return new ResultInfo(PROMPTS.PASSWORD_ENCRYPTION_FAILED);
        }

        // 直接注册用户
//        String hxAccount = Common.hxName + username;
        String hxAccount = Common.hxName + realUsername;
        String hxPwd;
        try {
//            hxPwd = EncrypMD5.eccrypt(username);
            hxPwd = EncrypMD5.eccrypt(realUsername);
        } catch (NoSuchAlgorithmException e1) {
            e1.printStackTrace();
//            return new ResultInfo("注册失败，请稍后再试");
            return new ResultInfo(PROMPTS.FAILED_REGISTER_USER);
        }
        //注册用户信息
//        StringBuffer sbBuffer = new StringBuffer("insert into ")
//                .append(PojoTables.UserInfo)
//                .append("(userType,username,telPhone,hxAccount,hxPassword,createTime)values")
//                .append("(").append(UserType.USER).append(",'").append(username).append("','").append(username).append("','")
//                .append(hxAccount).append("','").append(hxPwd).append("',").append(DateUtils.getCurrTime()).append(")");
        StringBuffer sbBuffer = new StringBuffer("insert into ")
                .append(PojoTables.UserInfo)
                .append("(userType,username,phone,telPhone,hxAccount,hxPassword,createTime)values")
                .append("(").append(UserType.USER).append(",'").append(realUsername).append("'").append(",'").append(username).append("','").append(username).append("','")
                .append(hxAccount).append("','").append(hxPwd).append("',").append(DateUtils.getCurrTime()).append(")");

        if (StringUtils.isNotBlank(email)) {
            sbBuffer = new StringBuffer("insert into ")
                    .append(PojoTables.UserInfo)
                    .append("(userType,username,phone,telPhone,hxAccount,hxPassword,createTime,email)values")
                    .append("(").append(UserType.USER).append(",'").append(realUsername).append("'").append(",'").append(username).append("','").append(username).append("','")
                    .append(hxAccount).append("','").append(hxPwd).append("',").append(DateUtils.getCurrTime()).append(",'").append(email).append("')");
        }

        //添加用户帐号信息
//        StringBuffer userPasql = new StringBuffer("INSERT INTO ").append(PojoTables.UserPasswordInfo).append("(username,password,createTime)values(")
//                .append("'").append(username).append("','").append(password).append("',").append(DateUtils.getCurrTime()).append(")");
        StringBuffer userPasql = new StringBuffer("INSERT INTO ").append(PojoTables.UserPasswordInfo).append("(username,password,createTime,hasSetPsw)values(")
                .append("'").append(realUsername).append("','").append(password).append("',").append(DateUtils.getCurrTime()).append(",").append(hasSetPsw).append(")");
        Connection conn;
        try {
            conn = UserDaoSql.getInstance().getConnection();
        } catch (SQLException e1) {
            e1.printStackTrace();
//            return new ResultInfo("注册失败，请稍后再试");
            return new ResultInfo(PROMPTS.FAILED_REGISTER_USER);
        }
        try {
            conn.setAutoCommit(false);
            UserDaoSql.getInstance().executeBySql(sbBuffer.toString(), conn);
            UserDaoSql.getInstance().executeBySql(userPasql.toString(), conn);


            conn.commit();
        } catch (Exception e) {
            UserDaoSql.getInstance().rollback(conn);
            e.printStackTrace();
//            return new ResultInfo("注册失败，请稍后再试");
            return new ResultInfo(PROMPTS.FAILED_REGISTER_USER);
        } finally {
            UserDaoSql.getInstance().close(conn);
        }

        //同步数据--增加帐号
        UserInfoMemory.getInstance().addUserInfo(realUsername);    //添加新用户
        UserPwdMemory.getInstance().getPassword(realUsername);    //添加新用户的密码缓存信息
        try {
            JMSNotify notify = JMSNotify.getInstance().setType(JMSTypeContent.USER_ADD).setStr01(realUsername);
            JmsSender.setTopicSender(notify);
        } catch (Exception e) {
        }

        Long time = DateUtils.getCurrTime();
        UserInfoExtra extra = UserInfoExtraMemory.getInstance().getByUsername(realUsername);
        if (null == extra) {
            //没有  新增
            UserInfoExtra userInfoExtra = new UserInfoExtra();
//            userInfoExtra.setUsername(username);
            userInfoExtra.setUsername(realUsername);
            userInfoExtra.setDelFlag(0);
            userInfoExtra.setCreateTime(time);
            userInfoExtra.setCreateUser(realUsername);
            if (ValidateUtil.isNotNull(devJson)) {// 设备信息
                userInfoExtra.setDevInfo(devJson);
            }
//            userInfoExtra.setCreateUser(username);
            try {
                UserDaoSql.getInstance().insertObj(PojoTables.USER_INFO_EXTRA, userInfoExtra);
            } catch (SQLException e) {
                e.printStackTrace();
            }
            UserInfoExtraMemory.getInstance().addOrModify(username);
        }


        return new ResultInfo();
    }

    //登录验证码是否正确
    private static ResultInfo loginTelCodeIsRight(String username, String telCode) {
        if (ValidateUtil.isNull(telCode)) {
//            return new ResultInfo("请填写验证码.");
            return new ResultInfo(PROMPTS.ENTER_VERIFICATION_CODE);
        } else {
            // 判断验证码是否正确
            HashMap<String, Object> map = new HashMap<String, Object>();
            map.put("username", username);
            List<HashMap<String, Object>> list = MongoDaoImpl.getInstance()
                    .find(UserSMSInfoParams.MonUserSMSDB, UserSMSInfoParams.MonUserSMSLoginCol, map, 1);
            if (list == null || list.size() < 1) {
//                return new ResultInfo("请获取验证码");
                return new ResultInfo(PROMPTS.ENTER_VERIFICATION_CODE);
            }
            // if (list.get(0).get("telCode") == null || list.get(0).get("telCode").toString().indexOf(telCode) < 0) {
            if (list.get(0).get("telCode") == null
                    || !list.get(0).get("telCode").toString().contains("\"" + telCode + "\"")) {
//                return new ResultInfo("请输入正确的验证码！");
                return new ResultInfo(PROMPTS.ENTER_CORRECT_VERIFY_CODE);
            }

            HashMap mapa = new HashMap();
            mapa.put("username", username);
            MongoDaoImpl.getInstance().delete(UserSMSInfoParams.MonUserSMSDB, UserSMSInfoParams.MonUserSMSLoginCol, mapa);
        }

        return new ResultInfo();
    }

    // -----------------------------------------------

    //统一登录接口 mod
    private static ResultInfo login(boolean loginOnly, String username, int loginUserType, boolean checkTelCode, boolean checkPassword, String password, String telCode, Boolean isXcx_, String devJson) {

        // 是否是实际的权限检查
        boolean isExactUserType = User.isExactUserType();
        //验证用户名和密码
//        UserInfo user = UserInfoMemory.getInstance().getUserInfo(username);
        UserInfo user = User.getUserInfoByUsername(username);
        boolean isFirstLogin = false;

        if (isXcx_) {
            checkTelCode = false;
        }
        if (user == null) {
            if (loginOnly) {// 仅登录
                return new ResultInfo(PROMPTS.USER_NOT_EXIST);
            } else { //验证码登录  没有的直接注册
                isFirstLogin = true;
                if (checkTelCode) {
                    // 判断验证码是否正确 1
                    ResultInfo info = loginTelCodeIsRight(username, telCode);//未注册登录
                    if (null == info) {
//                        return new ResultInfo("验证码验证错误，请重试");
                        return new ResultInfo(PROMPTS.VERIFICATION_CODE_ERROR);
                    }
                    if (null != info && !info.isSuccess()) {
                        return new ResultInfo(info.getError());
                    }
                }

                //注册用户
                ResultInfo resultInfo = registerByTelCode(username, false, password, telCode, true, null, devJson);//验证码登录
                if (null == resultInfo) {
//                    return new ResultInfo("验证码验证错误，请重试");
                    return new ResultInfo(PROMPTS.VERIFICATION_CODE_ERROR);
                }
                if (null != resultInfo && !resultInfo.isSuccess()) {
                    return new ResultInfo(resultInfo.getError());
                }

//                user = UserInfoMemory.getInstance().getUserInfo(username);
                user = User.getUserInfoByUsername(username);
                if (null == user) {
//                    return new ResultInfo("登录失败，请稍后再试");
                    return new ResultInfo(PROMPTS.LOGIN_ERROR);
                }
            }
        }

        if (null != user && User.isLocked(user.getIsLock())) {
//            return new ResultInfo("您的账号已锁定，请联系客服");
            return new ResultInfo(PROMPTS.ACCOUNT_IS_LOCKED);
        }


        //验证是否有登录权限
        int userType = user.getUserType();
        switch (loginUserType) {
            case UserType.ADMIN: {//管理员登录
//                if (0 == userType - UserType.ADMIN || 0 == userType - UserType.SUPER_ADMIN || 0 == userType - UserType.CUSTOMER_SERVICE || 0 == userType - UserType.FINANCE) {
//                } else {
////                    return new ResultInfo("您没有登录管理后台的权限，请联系客服");
//                    return new ResultInfo(PROMPTS.NO_ADMINISTRATIVE);
//                }
                if (!User.hasAdminAuth(userType)) {
                    return new ResultInfo(PROMPTS.NO_ADMINISTRATIVE);
                }
            }
            break;
            case UserType.USER: {//用户登录

            }
            break;
            case UserType.SHOP_OWNER: {//店主登录
                if (isExactUserType) {
                    // 多维的权限 谁都能登录

                } else {
                    if (userType != UserType.SHOP_OWNER) {
//                    return new ResultInfo("您不是店主无法登录");
                        return new ResultInfo(PROMPTS.NOT_SHOP_OWNER);
                    }
                }
//                if (userType != UserType.SHOP_OWNER) {
////                    return new ResultInfo("您不是店主无法登录");
//                    return new ResultInfo(PROMPTS.NOT_SHOP_OWNER);
//                }
//                ShopInfo shopInfo = ShopMemory.getInstance().getShopByUsername(username);
//                if (null == shopInfo) {
//                    return new ResultInfo("您不是店主无法登录!");
//                }
            }
            break;
            case UserType.POSTMAN: {//配送员登录
                if (isExactUserType) {
                } else {
                    if (userType != UserType.POSTMAN) {
//                    return new ResultInfo("您不是配送员无法登录");
                        return new ResultInfo(PROMPTS.NOT_DELIVERY_PERSON);
                    }
                    CityPostman cityPostman = CityPostmanMemory.getInstance().getPostman(user.getUsername());
                    if (null == cityPostman) {
                    }
                }
//                if (userType != UserType.POSTMAN) {
////                    return new ResultInfo("您不是配送员无法登录");
//                    return new ResultInfo(PROMPTS.NOT_DELIVERY_PERSON);
//                }
//                CityPostman cityPostman = CityPostmanMemory.getInstance().getPostman(username);
//                if (null == cityPostman) {
////                    return new ResultInfo("您不是配送员无法登录!");
////                    return new ResultInfo(PROMPTS.NOT_DELIVERY_PERSON);
//                }

            }
            break;
            case UserType.AGENT_MANAGER: {
                AgentManagerInfo agentManagerInfo = AgentManagerMemory.getInstance().get(username);
                if (agentManagerInfo == null) {
                    return new ResultInfo("您不是区域主管");
                }
            }
            break;
        }

        if (checkTelCode) {//验证码登录
            if (ValidateUtil.isNull(telCode)) {
//                return new ResultInfo("登录失败，请填写验证码");
                return new ResultInfo(PROMPTS.LOGIN_FAILED_BY_CODE);
            } else {
                if (!isFirstLogin) {
                    // 判断验证码是否正确
                    ResultInfo info = loginTelCodeIsRight(username, telCode);//已注册登录
                    if (null == info) {
//                        return new ResultInfo("验证码验证错误，请重试");
                        return new ResultInfo(PROMPTS.VERIFICATION_CODE_ERROR);
                    }
                    if (null != info && !info.isSuccess()) {
                        return new ResultInfo(info.getError());
                    }
                }
            }
        } else if (checkPassword) {//密码登录
            //判断密码
            try {
                password = EncrypMD5.eccrypt(password);
            } catch (NoSuchAlgorithmException e) {
                e.printStackTrace();
//            return new ResultInfo("密码错误，重新输入");
//                return new ResultInfo("用户名或密码错误，请重新输入");
                return new ResultInfo(PROMPTS.PASSWORD_IS_INCORRECT);
            }

//            String rpassword = UserPwdMemory.getInstance().getPassword(username);
            String rpassword = UserPwdMemory.getInstance().getPassword(user.getUsername());
            if (!password.equals(rpassword)) {
//            return new ResultInfo("密码错误，请输入正确密码");
//                return new ResultInfo("用户名或密码错误，请重新输入");
                return new ResultInfo(PROMPTS.PASSWORD_IS_INCORRECT);
            }
        }

        //返回token
        String token = ToolUtils.getToken();
        //缓存token
//        UserOnlineImpl.getInstance().add(token, username);
        UserOnlineImpl.getInstance().add(token, user.getUsername());

        //返回用户信息
        UserInfoVO userInfoVO = new UserInfoVO();
        try {
            ObjectUtils.copyPropertiesExclude(user, userInfoVO, null);
        } catch (Exception e) {
            e.printStackTrace();
//            return new ResultInfo("获取用户信息失败，请稍后再试");
            return new ResultInfo(PROMPTS.FAILED_GET_USER_INFORMATION);
        }
        if (null != userInfoVO) {
            if (ValidateUtil.isNotNull(userInfoVO.getSignPhoto()) && ValidateUtil.isNotNetUrl(userInfoVO.getSignPhoto())) {
//                userInfoVO.setSignPhoto(Common.imageUrl + userInfoVO.getSignPhoto());
                userInfoVO.setSignPhoto(SYS_CONFIG_PATH.IMAGE_BASE_URL + userInfoVO.getSignPhoto());
            }
        }
        userInfoVO.setToken(token);

//        UserWallet userWallet = UserWalletMemory.getInstance().getWallet(username);
//        if (null != userWallet) {
//            userInfoVO.setUserWallet(userWallet);
//        }

        UserWallet userWallet = WalletAction.getWallet(user.getUsername());
        if (null != userWallet) {
            userInfoVO.setUserWallet(userWallet);
        }
        //  检测用户是否设置支付密码了 create by yangtk
        String payPassword = UserPwdMemory.getInstance().getPayPassword(user.getUsername());

        if (payPassword != null && !"".equals(payPassword)) {
            userInfoVO.setHasPayPassword(1);
        }
        // end
        //记录日志
//        LoginLogMan.addLogin(username);
        LoginLogMan.addLogin(user.getUsername());

        return new ResultInfo("", userInfoVO);
    }



}
